﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;

namespace TMI85303.UI.UserControls
{

    public class WheelSlider : Slider
    {
        public WheelSlider()
        {
        }


        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            Value += e.Delta / 120;
            base.OnMouseWheel(e);
        }

        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {

            // 获取Slider的Track部件
            var track = (Track)this.Template.FindName("PART_Track", this);
            if (track == null)
            {
                base.OnPreviewMouseLeftButtonDown(e);
                return;
            }

            // 获取鼠标点击位置
            var position = e.GetPosition(track);

            // 检查点击位置是否在Thumb内
            var thumbRect = new Rect(track.Thumb.TranslatePoint(new Point(0, 0), track), new Size(track.Thumb.ActualWidth, track.Thumb.ActualHeight));
            if (!thumbRect.Contains(position))
            {
                // 如果点击位置不在Thumb内，则忽略此次点击，不对Slider的值进行更改
                e.Handled = true;
                return;
            }

            base.OnPreviewMouseLeftButtonDown(e);
        }


    }
}
